package cn.wokoba.service.activity.service.state.handler.event;

import cn.wokoba.service.activity.model.ActivityStateVO;
import cn.wokoba.service.activity.service.state.handler.AbstractActivityState;
import cn.wokoba.types.enums.ResponseCode;
import cn.wokoba.types.exception.AppException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component("checkState")
public class CheckState extends AbstractActivityState {
    @Override
    public boolean check(Long activityId, ActivityStateVO currentStatus) {
        log.error("审核状态不可重复审核 activityId:{}", activityId);
        throw new AppException(ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getCode(),ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getInfo());
    }

    @Override
    public boolean pass(Long activityId, ActivityStateVO currentStatus) {
        activityRepository.alterActivityState(activityId, currentStatus.getCode(), ActivityStateVO.pass.getCode());
        return true;
    }

    @Override
    public boolean closed(Long activityId, ActivityStateVO currentStatus) {
        log.error("审核状态不可进行关闭活动 activityId:{}", activityId);
        throw new AppException(ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getCode(),ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getInfo());
    }

    @Override
    public boolean create(Long activityId, ActivityStateVO currentStatus) {
        activityRepository.alterActivityState(activityId, currentStatus.getCode(), ActivityStateVO.create.getCode());
        return true;
    }

    @Override
    public boolean open(Long activityId, ActivityStateVO currentStatus) {
        log.error("审核状态不可直接开启活动 activityId:{}", activityId);
        throw new AppException(ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getCode(),ResponseCode.ACTIVITY_ALTER_STATE_ERROR.getInfo());
    }

    @Override
    public Enum<ActivityStateVO> getTypeEnum() {
        return ActivityStateVO.check;
    }
}
